package com.example.rabbitmqproducer.service;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Date;

@Service
public class RabbitmqSender {

    @PostConstruct
    private void init(){
        int i = 1;
        while (i < 100) {
            send();
            i++;
        }

    }

    @Resource
    private AmqpTemplate rabbitTemplate;

    public void send() {
        String context = "hello " + new Date();
        System.out.println("sender:" + context);
        rabbitTemplate.convertAndSend("hello", context);
    }
}
